package com.baihan.angus.app.game.busshow.ui.user.edit;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.baihan.angus.app.game.basic.base.BaseResponse;
import com.baihan.angus.app.game.basic.base.view_model.BaseViewModel;
import com.baihan.angus.app.game.basic.utils.Tooast;
import com.baihan.angus.app.game.basic.utils.net.ApiObserver;
import com.baihan.angus.app.game.common.bean.response.LoginResponse;
import com.baihan.angus.app.game.common.configs.UserConfig;
import com.baihan.angus.app.game.common.data_center.remote.RemoteDataMng;

import java.util.Map;

public class EditIntroVM extends BaseViewModel {

    public EditIntroVM(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Boolean> mldModifyResult = new MutableLiveData<>();

    public void modifyIntro(Map<String, Object> pMap) {
        showLoading("modifyIntro");
        RemoteDataMng.getInstance().modifyUserInfo(pMap, mLifecycleProvider.bindToLifecycle(), new ApiObserver<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                hideLoading("modifyIntro");
//                getUserInfo();
                mldModifyResult.setValue(true);
            }

            @Override
            public void onFailed(int code, String msg) {
                hideLoading("modifyIntro");
                mldModifyResult.setValue(false);
                Tooast.warning(msg);
            }
        });
    }

    public void getUserInfo() {
        showLoading("getUserInfo");
        RemoteDataMng.getInstance().getUserInfo(mLifecycleProvider.bindToLifecycle(), new ApiObserver<LoginResponse>() {
            @Override
            public void onSuccess(LoginResponse loginResponse) {
                hideLoading("getUserInfo");
                UserConfig.getUserConfig().saveUser(loginResponse.getData().getUserinfo());
                finish();
            }

            @Override
            public void onFailed(int code, String msg) {
                hideLoading("getUserInfo");
                Tooast.warning(msg);
            }
        });
    }
}
